import SyButton from './components/button/index';
import SyInput from './components/input/index';
import SySwitch from './components/switch/index';
import SyIcon from './components/icon/index';

import defaultLocal from './locale/zh-CN';

const SyUI = [
  SyInput,
  SyButton,
  SySwitch,
  SyIcon
];

const install = function (Vue, opts = {}) {
  SyUI.forEach(component => {
    Vue.component(component.name, component);
  });

  //初始化配置
  Vue.prototype.$IVIEW = {
    //主题
    theme: 'theme' in opts ? opts.theme : 'light',
    //默认大小
    size: opts.size || ''
  };


  //多主题  主题名就是主题class
  Vue.burgeonTheme = function (option) {
    document.querySelector('body').setAttribute('class', '');
    document.querySelector('body').setAttribute('class', option);
  };

  Vue.burgeonTheme(Vue.prototype.$IVIEW.theme);

  //多语言
  Vue.burgeonLocal = function (option) {
    Vue.prototype.burgeonLang = option;
  };

  Vue.burgeonLocal(defaultLocal);
};

/* 支持使用标签的方式引入 */
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue);
}

const API = { install, SyUI };

export default API;
